<template>
  <div>
    <el-dialog
      v-loading.lock="loading"
      :title="sysBusinessDetectionItem.methodStandards"
      align="center"
      class="base-dialog readonly"
      :custom-class="'panna-dialog_medium'"
      :close-on-click-modal="false"
      :visible.sync="productStandardDialogFormVisible"
    >
      <el-form ref="queryForm" :model="queryForm" inline>
        <el-form-item :label="sysBusinessDetectionItem.name" prop="orderNum">
          <el-input
            v-model="queryForm.productStandardName"
            :placeholder="sysBusinessDetectionItem.name"
            clearable
          />
        </el-form-item>
        <el-form-item class="base-filter-button">
          <el-button type="primary" @click="select">{{
            operateType.query
          }}</el-button>
          <el-button @click="cancelForm">{{ operateType.clear }}</el-button>
        </el-form-item>
      </el-form>

      <el-table
        :data="list"
        element-loading-text="Loading"
        fit
        highlight-current-row
        height="340px"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          align="center"
          :label="sysBusinessDetectionItem.serialNumber"
          width="50"
        >
          <template slot-scope="scope">{{ scope.$index + 1 }}</template>
        </el-table-column>
        <el-table-column :label="sysBusinessDetectionItem.name">
          <template slot-scope="scope">
            <a style="color: blue" @click="handleSelectionChange(scope.row)">{{
              scope.row.productStandardName
            }}</a>
          </template>
        </el-table-column>
        <el-table-column
          :label="sysBusinessDetectionItem.productStandardNumber"
        >
          <template slot-scope="scope">{{
            scope.row.nationalStandardNum
          }}</template>
        </el-table-column>
        <el-table-column :label="sysBusinessDetectionItem.tableNumber">
          <template slot-scope="scope">{{ scope.row.tableNum }}</template>
        </el-table-column>
        <el-table-column
          :label="sysBusinessDetectionItem.revocatoryDate"
          :formatter="formatTableTime"
        ></el-table-column>
      </el-table>
      <BasePagination
        :total="pagination.total"
        :page-index="pagination.pageIndex"
        :page-size="pagination.pageSize"
        @sizeChange="sizeChange"
        @changePage="currentChange"
      />
    </el-dialog>
  </div>
</template>

<script>
import { formatTime } from "../../../../utils/time";
export default {
  name: "ChoiceMethodStandard",
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      loading: false,
      list: [],
      // 复选框选中数据
      lists: [],
      productStandardDialogFormVisible: false,
      formLabelWidth: "200px",
      choiceData: {},
      queryForm: {
        productStandardName: "",
      },
      pagination: {
        pageIndex: 1,
        pageSize: 10,
        total: 0,
      },
    };
  },
  computed: {
    operateType() {
      return this.$t("ModuleSysBusiness.OperateType") || {};
    },
    sysBusinessDetectionItem() {
      return this.$t("SysBusinessDetectionItem") || {};
    },
  },
  watch: {
    dialogFormVisible(val) {
      this.productStandardDialogFormVisible = val;
    },
    productStandardDialogFormVisible(val) {
      this.$emit("update:dialogFormVisible", val);
    },
  },
  methods: {
    cancelForm() {
      this.queryForm.productStandardName = "";
      this.sizeChange(10);
    },
    select() {
      this.sizeChange(10);
    },
    formatTableTime(row) {
      if (row.revocatoryDate !== null && row.revocatoryDate !== "") {
        return formatTime(row.revocatoryDate);
      }
    },
    cancel() {
      this.$emit("dialogClose");
      this.productStandardDialogFormVisible = false;
    },
    closeDialog() {
      this.cancel();
    },
    handleSelectionChange(row) {
      this.choiceData = row;
      this.closeDialog();
    },
    currentChange(val) {
      this.pagination.pageIndex = val;
      this.$emit("getProductStandardList");
    },
    sizeChange(val) {
      this.pagination.pageIndex = 1;
      this.pagination.pageSize = val;
      this.$emit("getProductStandardList");
    },
  },
};
</script>
